package top.yongyan0624.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import top.yongyan0624.Utils.RedisUtil;
import top.yongyan0624.common.lang.CodeMsg;
import top.yongyan0624.common.lang.ResultVO;
import top.yongyan0624.entity.Count;
import top.yongyan0624.service.CountService;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yongyan
 * @since 2021-05-19
 */
@RestController
public class CountController extends BaseController {

    @Autowired
    private CountService countService;

    @PostMapping("/leavingMessage/count")
    public ResultVO setCount(@RequestBody Count count) {
        if (count.getMsgId() == null || count.getUserId() == null || count.getPostId() == null) {
            return ResultVO.error(new CodeMsg("留言id、作者id、点赞者id不能为空！"));
        }

        countService.setCount(count);

        return ResultVO.success("操作成功!");
    }

    @PostMapping("/leavingMessage/getCountById")
    public ResultVO getCountById(@RequestBody Count count) {
        if (count.getMsgId() == null || count.getUserId() == null || count.getPostId() == null) {
            return ResultVO.error(new CodeMsg("留言id、作者id、点赞者id不能为空！"));
        }

        countService.handleCache(count);

        return ResultVO.success(count);
    }

}
